package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.entity.*;
import com.dk.mapper.*;
import com.dk.service.IDtRecycleBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lebron
 * @since 2021-12-22
 */
@Service
public class DtRecycleBrandServiceImpl extends ServiceImpl<DtRecycleBrandMapper, DtRecycleBrand> implements IDtRecycleBrandService {
    @Autowired
    private DtRecycleBrandMapper recycleBrandMapper;
    @Autowired
    private DtDeatilTypeMapper dtDeatilTypeMapper;
    @Autowired
    private DtBrandTypeMapper brandTypeMapper;
    @Autowired
    private DtSpecMapper specMapper;
    @Autowired
    private DtCtcRecycleMapper ctcRecycleMapper;
    @Autowired
    private DtGoodsMapper goodsMapper;
    @Autowired
    private DtItemMapper itemMapper;
    @Override
    public List<DtRecycleBrand> selectList() {
        return recycleBrandMapper.selectList(null);
    }

    @Override
    public List<DtSpec> specBrandById(Integer id) {
        QueryWrapper<DtSpec> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("detail_id",id);
        return  specMapper.selectList(queryWrapper);
    }

    @Override
    public List<DtBrandType> typeBrandById(Integer id) {
        QueryWrapper<DtBrandType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("band_id",id);
        return  brandTypeMapper.selectList(queryWrapper);
    }

    @Override
    public List<DtDeatilType> detailBrandById(Integer id) {
        QueryWrapper<DtDeatilType> wrapper = new QueryWrapper<>();
        wrapper.eq("type_id",id);
        return dtDeatilTypeMapper.selectList(wrapper);
    }

    @Override
    public int insertRecycle(DtCtcRecycle recycle) {
      return  ctcRecycleMapper.insert(recycle);
    }

    @Override
    @Transactional
    public int insertGoodsAndItem(DtGoods dtGoods, DtItem dtItem) {
        int insert = goodsMapper.insert(dtGoods);
        Long goodsId = dtGoods.getId();
        dtItem.setGoodsId(goodsId);

        return itemMapper.insert(dtItem);
    }
}
